#ifndef RELU_H
#define RELU_H

#include <cmath>
#include "activation_function.h"

class ReLU : public ActivationFunction {
public:
    // ReLU激活函数
    std::vector<std::vector<float>> apply(const std::vector<std::vector<float>>& Z) {
        std::vector<std::vector<float>> A(Z.size(), std::vector<float>(Z[0].size()));
        for (size_t i = 0; i < Z.size(); ++i) {
            for (size_t j = 0; j < Z[i].size(); ++j) {
                A[i][j] = std::max(0.0f, Z[i][j]);
            }
        }
        return A;
    }

    // ReLU激活函数的导数
    std::vector<std::vector<float>> applyDerivative(const std::vector<std::vector<float>>& Z) {
        std::vector<std::vector<float>> D(Z.size(), std::vector<float>(Z[0].size()));
        for (size_t i = 0; i < Z.size(); ++i) {
            for (size_t j = 0; j < Z[i].size(); ++j) {
                D[i][j] = Z[i][j] > 0 ? 1.0 : 0.0;
            }
        }
        return D;
    }

    std::string getType(){
        return "ReLU";
    }
};

#endif // RELU_H
